#!/bin/bash
# chinese:默认LVS不带健康检查功能，需要自己手动编写动态检测脚本，实现该功能
# The default LVS has no health check function, 
# so it is necessary to manually write shell
# scripts to realize this function.
VIP=192.168.4.15:80
RIP1=192.168.4.100
RIP2=192.168.4.200
while :
do
    for IP in $RIP1 $RIP2
    do
        curl -s http://$IP &> /dev/null
        if [ $? -eq 0 ];then
            ipvsadm -Ln | grep -q $IP || ipvsadm -a -t $VIP -r $IP
        else
            ipvsadm -Ln | grep -q $IP && ipvsadm -a -t $VIP -r $IP
        fi
    done
    sleep 1 #for rest every 1 s
done
